package com.zero.mxshengadmin.modules.website.controller;

import com.zero.mxshengadmin.common.utils.PageUtils;
import com.zero.mxshengadmin.common.utils.R;
import com.zero.mxshengadmin.common.validator.ValidatorUtils;
import com.zero.mxshengadmin.modules.website.entity.WebsiteAdvertiseEntity;
import com.zero.mxshengadmin.modules.website.service.WebsiteAdvertiseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created by aicaikeji on 2019/4/3.
 */

@RestController
public class WebsiteAdvertiseController {
    @Autowired
    private WebsiteAdvertiseService websiteAdvertiseService;

    /**
     * 添加招聘
     * @param entity
     * @return
     */
    @PostMapping("/website/advertise/add")
    public R save(@RequestBody WebsiteAdvertiseEntity entity) {
        ValidatorUtils.validateEntity(entity);
        websiteAdvertiseService.save(entity);
        return R.ok();
    }

    /**
     * 删除招聘
     * @param ids
     * @return
     */
    @PostMapping("/website/advertise/delete")
    public R delete(@RequestBody Long[] ids) {
        websiteAdvertiseService.removeByIds(ids);
        return R.ok();
    }

    /**
     * 更新招聘
     * @param entity
     * @return
     */
    @PostMapping("/website/advertise/update")
    public R update(@RequestBody WebsiteAdvertiseEntity entity) {
        websiteAdvertiseService.update(entity);
        return R.ok();
    }

    /**
     * 查询某条招聘
     * @param id
     * @return
     */
    @GetMapping("/website/advertise/find/{id}")
    public R find(@PathVariable("id") Long id) {
        WebsiteAdvertiseEntity entity = websiteAdvertiseService.getById(id);
        return R.ok().put("result",entity);
    }

    /**
     * 查询招聘列表
     * @param params
     * @return
     */
    @PostMapping("/website/advertise/list")
    public R findList(@RequestParam Map<String, Object> params) {
        PageUtils page = websiteAdvertiseService.queryPage(params);
        return R.ok().put("result", page);
    }
}
